package com.zx.mes.hyl.queue;

import com.zx.mes.hyl.array.HArray;

/**
 * @author huayunlong
 * @date
 *
 */
public class ArrayQueue<E> implements Queue<E>{

    private int size;

    private HArray<E> array;


    public ArrayQueue(int capacity){
        array = new HArray<>(capacity);
    }

    public ArrayQueue(){
        array = new HArray<>(10);
    }

    public boolean isEmpty(){
        return size == 0;
    }


    @Override
    public void enqueue(E e) {
        array.add(e);
        size++;
    }

    @Override
    public void dequeue() {
        array.removeFirst();
        size--;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("队列:[");
        for (int i = 0; i <array.length() ; i++) {
            sb.append(array.get(i));
            if (i < array.length()-1) {
                sb.append(",");
            }
        }
        sb.append("] " + array.length());
        return sb.toString();
    }
}
